{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "class ParameterTuner():\n",
    "    def __init__(self):\n",
    "        pass\n",
    "    \n",
    "    def grid_search(self):\n",
    "        pass\n",
    "    \n",
    "    def random_search(self):\n",
    "        pass\n",
    "    \n",
    "    def "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "import random\n",
    "\n",
    "\n",
    "\n",
    "def test():\n",
    "    bs = BayesianSmoothing(1, 1)\n",
    "    I, C = bs.sample(500, 500, 1000, 10000)\n",
    "    print I, C\n",
    "    bs.update(I, C, 1000, 0.0000000001)\n",
    "    print bs.alpha, bs.beta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1: [0.1995321232978925, 0.4584005150038477, 0.728139286515725]\n",
      "2: [0.1765306828682771, 0.5410222759696705]\n",
      "5: [0.4520541017238462, 0.7231685910471085]\n",
      "13: [0.32307661218088957, 0.5562492721961102]\n",
      "['1_discret', '2_discret', '5_discret', '13_discret']\n",
      "    1_discret  2_discret  5_discret  13_discret         1         2         5  \\\n",
      "0           0          0          0           0  0.014441  0.073506  0.059459   \n",
      "1           1          0          2           0  0.289472  0.021901  0.828331   \n",
      "2           3          2          1           2  0.826716  0.778555  0.527616   \n",
      "3           0          2          1           2  0.169692  0.930278  0.653557   \n",
      "4           1          2          1           2  0.394006  0.553695  0.608644   \n",
      "5           3          1          0           2  0.959307  0.241897  0.237872   \n",
      "6           2          1          1           0  0.462319  0.239300  0.526235   \n",
      "7           0          2          2           1  0.054348  0.854424  0.993454   \n",
      "8           2          0          2           0  0.671590  0.027689  0.883703   \n",
      "9           2          2          0           0  0.465913  0.871011  0.120904   \n",
      "10          0          0          0           0  0.122301  0.039548  0.417243   \n",
      "11          2          1          0           2  0.501103  0.236245  0.452054   \n",
      "12          1          1          2           1  0.255558  0.266673  0.948327   \n",
      "13          3          0          0           0  0.898216  0.161326  0.155145   \n",
      "14          2          0          2           1  0.728139  0.159766  0.765365   \n",
      "15          3          1          2           0  0.973591  0.250169  0.724618   \n",
      "16          1          1          0           2  0.458401  0.475500  0.344501   \n",
      "17          3          2          2           1  0.768950  0.612886  0.890614   \n",
      "18          1          2          0           1  0.354848  0.613827  0.377409   \n",
      "19          1          1          0           1  0.367935  0.249358  0.122568   \n",
      "20          0          2          1           2  0.199532  0.906798  0.453732   \n",
      "21          1          1          1           0  0.304167  0.483428  0.466067   \n",
      "22          3          2          0           2  0.937924  0.770070  0.036664   \n",
      "23          0          2          0           0  0.002147  0.740764  0.024179   \n",
      "24          3          2          1           0  0.997116  0.892325  0.723169   \n",
      "25          1          0          2           0  0.234465  0.074195  0.724429   \n",
      "26          0          1          0           2  0.117123  0.450465  0.001330   \n",
      "27          0          1          1           1  0.156509  0.232795  0.697533   \n",
      "28          2          2          0           2  0.665243  0.838468  0.437896   \n",
      "29          2          2          1           0  0.592058  0.952345  0.624151   \n",
      "30          1          1          0           2  0.427029  0.272087  0.286482   \n",
      "31          1          2          2           0  0.312527  0.558691  0.999391   \n",
      "32          3          0          1           2  0.806497  0.021480  0.672740   \n",
      "33          2          1          1           2  0.649341  0.318714  0.709483   \n",
      "34          3          0          2           0  0.970139  0.176531  0.734165   \n",
      "35          3          1          2           2  0.997465  0.437610  0.879230   \n",
      "36          0          1          2           0  0.186767  0.456297  0.847329   \n",
      "37          2          0          2           0  0.559453  0.154393  0.784599   \n",
      "38          1          2          0           0  0.349343  0.868602  0.416360   \n",
      "39          3          1          1           1  0.893388  0.442108  0.500536   \n",
      "40          2          0          2           0  0.570962  0.136585  0.851072   \n",
      "41          0          2          1           0  0.187156  0.976505  0.486107   \n",
      "42          2          1          2           1  0.589830  0.181476  0.885977   \n",
      "43          0          2          0           1  0.053570  0.715351  0.257805   \n",
      "44          2          2          0           1  0.698178  0.997120  0.000798   \n",
      "45          1          1          0           2  0.298504  0.541022  0.115253   \n",
      "46          2          2          0           1  0.595141  0.583184  0.125274   \n",
      "47          3          1          2           0  0.767100  0.498194  0.830309   \n",
      "48          3          1          0           0  0.807063  0.384843  0.313818   \n",
      "49          3          2          0           1  0.758598  0.785587  0.016488   \n",
      "\n",
      "          13  \n",
      "0   0.029295  \n",
      "1   0.215454  \n",
      "2   0.713442  \n",
      "3   0.679013  \n",
      "4   0.809576  \n",
      "5   0.999673  \n",
      "6   0.199257  \n",
      "7   0.501470  \n",
      "8   0.182063  \n",
      "9   0.012207  \n",
      "10  0.270331  \n",
      "11  0.560863  \n",
      "12  0.405770  \n",
      "13  0.078619  \n",
      "14  0.328537  \n",
      "15  0.292266  \n",
      "16  0.574509  \n",
      "17  0.426609  \n",
      "18  0.556249  \n",
      "19  0.337629  \n",
      "20  0.976224  \n",
      "21  0.258158  \n",
      "22  0.942145  \n",
      "23  0.214838  \n",
      "24  0.208792  \n",
      "25  0.073630  \n",
      "26  0.866819  \n",
      "27  0.456441  \n",
      "28  0.745625  \n",
      "29  0.174308  \n",
      "30  0.995506  \n",
      "31  0.323077  \n",
      "32  0.685625  \n",
      "33  0.778230  \n",
      "34  0.314112  \n",
      "35  0.925972  \n",
      "36  0.138769  \n",
      "37  0.040404  \n",
      "38  0.054106  \n",
      "39  0.374761  \n",
      "40  0.247221  \n",
      "41  0.061042  \n",
      "42  0.450578  \n",
      "43  0.522424  \n",
      "44  0.455755  \n",
      "45  0.894834  \n",
      "46  0.502476  \n",
      "47  0.034775  \n",
      "48  0.198826  \n",
      "49  0.379260  \n"
     ]
    }
   ],
   "source": [
    "data = pd.DataFrame(np.random.random((50,30)), columns=[str(i) for i in range(30)])\n",
    "labels = np.random.randint(0,2,(50,))\n",
    "fs = FeatureDetector(data, labels)\n",
    "new_features = fs.detect_continuous_split([\"1\", \"2\", \"5\", \"13\"], min_split_num=10)\n",
    "print(new_features)\n",
    "print(fs.features[new_features + [\"1\", \"2\", \"5\", \"13\"]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    11\n",
      "1    12\n",
      "2    13\n",
      "3    14\n",
      "Name: 1_discret, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(fs.features[\"1_discret\"].value_counts().sort_index())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "s = pd.Series([1,2,3,1], index=range(1,5), name=\"test\")\n",
    "for e in s:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[9 8 3 2 6 4 7 1 5]\n",
      "[1 2 4 8 6 5 9 3 7]\n",
      "['9_1' '8_2' '3_4' '3_8' '8_4' '2_2' '6_4' '9_6' '8_8' '9_2' '3_5' '4_9'\n",
      " '7_4' '3_3' '2_6' '6_7' '1_3' '1_5' '4_5' '1_7' '8_9' '2_4' '5_7' '2_9'\n",
      " '1_2' '6_5' '9_9' '9_4' '7_3' '5_1' '3_9' '6_8' '6_6' '9_3']\n",
      "9\n",
      "9\n",
      "34\n"
     ]
    }
   ],
   "source": [
    "print(fs.features[\"1\"].unique())\n",
    "print(fs.features[\"2\"].unique())\n",
    "print(fs.features[\"1_2\"].unique())\n",
    "\n",
    "print(len(fs.features[\"1\"].unique()))\n",
    "print(len(fs.features[\"2\"].unique()))\n",
    "print(len(fs.features[\"1_2\"].unique()))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3)\n",
      "(1, 2, 4)\n",
      "(1, 2, 5)\n",
      "(1, 2, 6)\n",
      "(1, 2, 7)\n",
      "(1, 2, 8)\n",
      "(1, 2, 9)\n",
      "(1, 2, 10)\n",
      "(1, 2, 11)\n",
      "(1, 2, 12)\n",
      "(1, 2, 13)\n",
      "(1, 2, 14)\n",
      "(1, 2, 15)\n",
      "(1, 2, 16)\n",
      "(1, 2, 17)\n",
      "(1, 2, 18)\n",
      "(1, 2, 19)\n",
      "(1, 3, 4)\n",
      "(1, 3, 5)\n",
      "(1, 3, 6)\n",
      "(1, 3, 7)\n",
      "(1, 3, 8)\n",
      "(1, 3, 9)\n",
      "(1, 3, 10)\n",
      "(1, 3, 11)\n",
      "(1, 3, 12)\n",
      "(1, 3, 13)\n",
      "(1, 3, 14)\n",
      "(1, 3, 15)\n",
      "(1, 3, 16)\n",
      "(1, 3, 17)\n",
      "(1, 3, 18)\n",
      "(1, 3, 19)\n",
      "(1, 4, 5)\n",
      "(1, 4, 6)\n",
      "(1, 4, 7)\n",
      "(1, 4, 8)\n",
      "(1, 4, 9)\n",
      "(1, 4, 10)\n",
      "(1, 4, 11)\n",
      "(1, 4, 12)\n",
      "(1, 4, 13)\n",
      "(1, 4, 14)\n",
      "(1, 4, 15)\n",
      "(1, 4, 16)\n",
      "(1, 4, 17)\n",
      "(1, 4, 18)\n",
      "(1, 4, 19)\n",
      "(1, 5, 6)\n",
      "(1, 5, 7)\n",
      "(1, 5, 8)\n",
      "(1, 5, 9)\n",
      "(1, 5, 10)\n",
      "(1, 5, 11)\n",
      "(1, 5, 12)\n",
      "(1, 5, 13)\n",
      "(1, 5, 14)\n",
      "(1, 5, 15)\n",
      "(1, 5, 16)\n",
      "(1, 5, 17)\n",
      "(1, 5, 18)\n",
      "(1, 5, 19)\n",
      "(1, 6, 7)\n",
      "(1, 6, 8)\n",
      "(1, 6, 9)\n",
      "(1, 6, 10)\n",
      "(1, 6, 11)\n",
      "(1, 6, 12)\n",
      "(1, 6, 13)\n",
      "(1, 6, 14)\n",
      "(1, 6, 15)\n",
      "(1, 6, 16)\n",
      "(1, 6, 17)\n",
      "(1, 6, 18)\n",
      "(1, 6, 19)\n",
      "(1, 7, 8)\n",
      "(1, 7, 9)\n",
      "(1, 7, 10)\n",
      "(1, 7, 11)\n",
      "(1, 7, 12)\n",
      "(1, 7, 13)\n",
      "(1, 7, 14)\n",
      "(1, 7, 15)\n",
      "(1, 7, 16)\n",
      "(1, 7, 17)\n",
      "(1, 7, 18)\n",
      "(1, 7, 19)\n",
      "(1, 8, 9)\n",
      "(1, 8, 10)\n",
      "(1, 8, 11)\n",
      "(1, 8, 12)\n",
      "(1, 8, 13)\n",
      "(1, 8, 14)\n",
      "(1, 8, 15)\n",
      "(1, 8, 16)\n",
      "(1, 8, 17)\n",
      "(1, 8, 18)\n",
      "(1, 8, 19)\n",
      "(1, 9, 10)\n",
      "(1, 9, 11)\n",
      "(1, 9, 12)\n",
      "(1, 9, 13)\n",
      "(1, 9, 14)\n",
      "(1, 9, 15)\n",
      "(1, 9, 16)\n",
      "(1, 9, 17)\n",
      "(1, 9, 18)\n",
      "(1, 9, 19)\n",
      "(1, 10, 11)\n",
      "(1, 10, 12)\n",
      "(1, 10, 13)\n",
      "(1, 10, 14)\n",
      "(1, 10, 15)\n",
      "(1, 10, 16)\n",
      "(1, 10, 17)\n",
      "(1, 10, 18)\n",
      "(1, 10, 19)\n",
      "(1, 11, 12)\n",
      "(1, 11, 13)\n",
      "(1, 11, 14)\n",
      "(1, 11, 15)\n",
      "(1, 11, 16)\n",
      "(1, 11, 17)\n",
      "(1, 11, 18)\n",
      "(1, 11, 19)\n",
      "(1, 12, 13)\n",
      "(1, 12, 14)\n",
      "(1, 12, 15)\n",
      "(1, 12, 16)\n",
      "(1, 12, 17)\n",
      "(1, 12, 18)\n",
      "(1, 12, 19)\n",
      "(1, 13, 14)\n",
      "(1, 13, 15)\n",
      "(1, 13, 16)\n",
      "(1, 13, 17)\n",
      "(1, 13, 18)\n",
      "(1, 13, 19)\n",
      "(1, 14, 15)\n",
      "(1, 14, 16)\n",
      "(1, 14, 17)\n",
      "(1, 14, 18)\n",
      "(1, 14, 19)\n",
      "(1, 15, 16)\n",
      "(1, 15, 17)\n",
      "(1, 15, 18)\n",
      "(1, 15, 19)\n",
      "(1, 16, 17)\n",
      "(1, 16, 18)\n",
      "(1, 16, 19)\n",
      "(1, 17, 18)\n",
      "(1, 17, 19)\n",
      "(1, 18, 19)\n",
      "(2, 3, 4)\n",
      "(2, 3, 5)\n",
      "(2, 3, 6)\n",
      "(2, 3, 7)\n",
      "(2, 3, 8)\n",
      "(2, 3, 9)\n",
      "(2, 3, 10)\n",
      "(2, 3, 11)\n",
      "(2, 3, 12)\n",
      "(2, 3, 13)\n",
      "(2, 3, 14)\n",
      "(2, 3, 15)\n",
      "(2, 3, 16)\n",
      "(2, 3, 17)\n",
      "(2, 3, 18)\n",
      "(2, 3, 19)\n",
      "(2, 4, 5)\n",
      "(2, 4, 6)\n",
      "(2, 4, 7)\n",
      "(2, 4, 8)\n",
      "(2, 4, 9)\n",
      "(2, 4, 10)\n",
      "(2, 4, 11)\n",
      "(2, 4, 12)\n",
      "(2, 4, 13)\n",
      "(2, 4, 14)\n",
      "(2, 4, 15)\n",
      "(2, 4, 16)\n",
      "(2, 4, 17)\n",
      "(2, 4, 18)\n",
      "(2, 4, 19)\n",
      "(2, 5, 6)\n",
      "(2, 5, 7)\n",
      "(2, 5, 8)\n",
      "(2, 5, 9)\n",
      "(2, 5, 10)\n",
      "(2, 5, 11)\n",
      "(2, 5, 12)\n",
      "(2, 5, 13)\n",
      "(2, 5, 14)\n",
      "(2, 5, 15)\n",
      "(2, 5, 16)\n",
      "(2, 5, 17)\n",
      "(2, 5, 18)\n",
      "(2, 5, 19)\n",
      "(2, 6, 7)\n",
      "(2, 6, 8)\n",
      "(2, 6, 9)\n",
      "(2, 6, 10)\n",
      "(2, 6, 11)\n",
      "(2, 6, 12)\n",
      "(2, 6, 13)\n",
      "(2, 6, 14)\n",
      "(2, 6, 15)\n",
      "(2, 6, 16)\n",
      "(2, 6, 17)\n",
      "(2, 6, 18)\n",
      "(2, 6, 19)\n",
      "(2, 7, 8)\n",
      "(2, 7, 9)\n",
      "(2, 7, 10)\n",
      "(2, 7, 11)\n",
      "(2, 7, 12)\n",
      "(2, 7, 13)\n",
      "(2, 7, 14)\n",
      "(2, 7, 15)\n",
      "(2, 7, 16)\n",
      "(2, 7, 17)\n",
      "(2, 7, 18)\n",
      "(2, 7, 19)\n",
      "(2, 8, 9)\n",
      "(2, 8, 10)\n",
      "(2, 8, 11)\n",
      "(2, 8, 12)\n",
      "(2, 8, 13)\n",
      "(2, 8, 14)\n",
      "(2, 8, 15)\n",
      "(2, 8, 16)\n",
      "(2, 8, 17)\n",
      "(2, 8, 18)\n",
      "(2, 8, 19)\n",
      "(2, 9, 10)\n",
      "(2, 9, 11)\n",
      "(2, 9, 12)\n",
      "(2, 9, 13)\n",
      "(2, 9, 14)\n",
      "(2, 9, 15)\n",
      "(2, 9, 16)\n",
      "(2, 9, 17)\n",
      "(2, 9, 18)\n",
      "(2, 9, 19)\n",
      "(2, 10, 11)\n",
      "(2, 10, 12)\n",
      "(2, 10, 13)\n",
      "(2, 10, 14)\n",
      "(2, 10, 15)\n",
      "(2, 10, 16)\n",
      "(2, 10, 17)\n",
      "(2, 10, 18)\n",
      "(2, 10, 19)\n",
      "(2, 11, 12)\n",
      "(2, 11, 13)\n",
      "(2, 11, 14)\n",
      "(2, 11, 15)\n",
      "(2, 11, 16)\n",
      "(2, 11, 17)\n",
      "(2, 11, 18)\n",
      "(2, 11, 19)\n",
      "(2, 12, 13)\n",
      "(2, 12, 14)\n",
      "(2, 12, 15)\n",
      "(2, 12, 16)\n",
      "(2, 12, 17)\n",
      "(2, 12, 18)\n",
      "(2, 12, 19)\n",
      "(2, 13, 14)\n",
      "(2, 13, 15)\n",
      "(2, 13, 16)\n",
      "(2, 13, 17)\n",
      "(2, 13, 18)\n",
      "(2, 13, 19)\n",
      "(2, 14, 15)\n",
      "(2, 14, 16)\n",
      "(2, 14, 17)\n",
      "(2, 14, 18)\n",
      "(2, 14, 19)\n",
      "(2, 15, 16)\n",
      "(2, 15, 17)\n",
      "(2, 15, 18)\n",
      "(2, 15, 19)\n",
      "(2, 16, 17)\n",
      "(2, 16, 18)\n",
      "(2, 16, 19)\n",
      "(2, 17, 18)\n",
      "(2, 17, 19)\n",
      "(2, 18, 19)\n",
      "(3, 4, 5)\n",
      "(3, 4, 6)\n",
      "(3, 4, 7)\n",
      "(3, 4, 8)\n",
      "(3, 4, 9)\n",
      "(3, 4, 10)\n",
      "(3, 4, 11)\n",
      "(3, 4, 12)\n",
      "(3, 4, 13)\n",
      "(3, 4, 14)\n",
      "(3, 4, 15)\n",
      "(3, 4, 16)\n",
      "(3, 4, 17)\n",
      "(3, 4, 18)\n",
      "(3, 4, 19)\n",
      "(3, 5, 6)\n",
      "(3, 5, 7)\n",
      "(3, 5, 8)\n",
      "(3, 5, 9)\n",
      "(3, 5, 10)\n",
      "(3, 5, 11)\n",
      "(3, 5, 12)\n",
      "(3, 5, 13)\n",
      "(3, 5, 14)\n",
      "(3, 5, 15)\n",
      "(3, 5, 16)\n",
      "(3, 5, 17)\n",
      "(3, 5, 18)\n",
      "(3, 5, 19)\n",
      "(3, 6, 7)\n",
      "(3, 6, 8)\n",
      "(3, 6, 9)\n",
      "(3, 6, 10)\n",
      "(3, 6, 11)\n",
      "(3, 6, 12)\n",
      "(3, 6, 13)\n",
      "(3, 6, 14)\n",
      "(3, 6, 15)\n",
      "(3, 6, 16)\n",
      "(3, 6, 17)\n",
      "(3, 6, 18)\n",
      "(3, 6, 19)\n",
      "(3, 7, 8)\n",
      "(3, 7, 9)\n",
      "(3, 7, 10)\n",
      "(3, 7, 11)\n",
      "(3, 7, 12)\n",
      "(3, 7, 13)\n",
      "(3, 7, 14)\n",
      "(3, 7, 15)\n",
      "(3, 7, 16)\n",
      "(3, 7, 17)\n",
      "(3, 7, 18)\n",
      "(3, 7, 19)\n",
      "(3, 8, 9)\n",
      "(3, 8, 10)\n",
      "(3, 8, 11)\n",
      "(3, 8, 12)\n",
      "(3, 8, 13)\n",
      "(3, 8, 14)\n",
      "(3, 8, 15)\n",
      "(3, 8, 16)\n",
      "(3, 8, 17)\n",
      "(3, 8, 18)\n",
      "(3, 8, 19)\n",
      "(3, 9, 10)\n",
      "(3, 9, 11)\n",
      "(3, 9, 12)\n",
      "(3, 9, 13)\n",
      "(3, 9, 14)\n",
      "(3, 9, 15)\n",
      "(3, 9, 16)\n",
      "(3, 9, 17)\n",
      "(3, 9, 18)\n",
      "(3, 9, 19)\n",
      "(3, 10, 11)\n",
      "(3, 10, 12)\n",
      "(3, 10, 13)\n",
      "(3, 10, 14)\n",
      "(3, 10, 15)\n",
      "(3, 10, 16)\n",
      "(3, 10, 17)\n",
      "(3, 10, 18)\n",
      "(3, 10, 19)\n",
      "(3, 11, 12)\n",
      "(3, 11, 13)\n",
      "(3, 11, 14)\n",
      "(3, 11, 15)\n",
      "(3, 11, 16)\n",
      "(3, 11, 17)\n",
      "(3, 11, 18)\n",
      "(3, 11, 19)\n",
      "(3, 12, 13)\n",
      "(3, 12, 14)\n",
      "(3, 12, 15)\n",
      "(3, 12, 16)\n",
      "(3, 12, 17)\n",
      "(3, 12, 18)\n",
      "(3, 12, 19)\n",
      "(3, 13, 14)\n",
      "(3, 13, 15)\n",
      "(3, 13, 16)\n",
      "(3, 13, 17)\n",
      "(3, 13, 18)\n",
      "(3, 13, 19)\n",
      "(3, 14, 15)\n",
      "(3, 14, 16)\n",
      "(3, 14, 17)\n",
      "(3, 14, 18)\n",
      "(3, 14, 19)\n",
      "(3, 15, 16)\n",
      "(3, 15, 17)\n",
      "(3, 15, 18)\n",
      "(3, 15, 19)\n",
      "(3, 16, 17)\n",
      "(3, 16, 18)\n",
      "(3, 16, 19)\n",
      "(3, 17, 18)\n",
      "(3, 17, 19)\n",
      "(3, 18, 19)\n",
      "(4, 5, 6)\n",
      "(4, 5, 7)\n",
      "(4, 5, 8)\n",
      "(4, 5, 9)\n",
      "(4, 5, 10)\n",
      "(4, 5, 11)\n",
      "(4, 5, 12)\n",
      "(4, 5, 13)\n",
      "(4, 5, 14)\n",
      "(4, 5, 15)\n",
      "(4, 5, 16)\n",
      "(4, 5, 17)\n",
      "(4, 5, 18)\n",
      "(4, 5, 19)\n",
      "(4, 6, 7)\n",
      "(4, 6, 8)\n",
      "(4, 6, 9)\n",
      "(4, 6, 10)\n",
      "(4, 6, 11)\n",
      "(4, 6, 12)\n",
      "(4, 6, 13)\n",
      "(4, 6, 14)\n",
      "(4, 6, 15)\n",
      "(4, 6, 16)\n",
      "(4, 6, 17)\n",
      "(4, 6, 18)\n",
      "(4, 6, 19)\n",
      "(4, 7, 8)\n",
      "(4, 7, 9)\n",
      "(4, 7, 10)\n",
      "(4, 7, 11)\n",
      "(4, 7, 12)\n",
      "(4, 7, 13)\n",
      "(4, 7, 14)\n",
      "(4, 7, 15)\n",
      "(4, 7, 16)\n",
      "(4, 7, 17)\n",
      "(4, 7, 18)\n",
      "(4, 7, 19)\n",
      "(4, 8, 9)\n",
      "(4, 8, 10)\n",
      "(4, 8, 11)\n",
      "(4, 8, 12)\n",
      "(4, 8, 13)\n",
      "(4, 8, 14)\n",
      "(4, 8, 15)\n",
      "(4, 8, 16)\n",
      "(4, 8, 17)\n",
      "(4, 8, 18)\n",
      "(4, 8, 19)\n",
      "(4, 9, 10)\n",
      "(4, 9, 11)\n",
      "(4, 9, 12)\n",
      "(4, 9, 13)\n",
      "(4, 9, 14)\n",
      "(4, 9, 15)\n",
      "(4, 9, 16)\n",
      "(4, 9, 17)\n",
      "(4, 9, 18)\n",
      "(4, 9, 19)\n",
      "(4, 10, 11)\n",
      "(4, 10, 12)\n",
      "(4, 10, 13)\n",
      "(4, 10, 14)\n",
      "(4, 10, 15)\n",
      "(4, 10, 16)\n",
      "(4, 10, 17)\n",
      "(4, 10, 18)\n",
      "(4, 10, 19)\n",
      "(4, 11, 12)\n",
      "(4, 11, 13)\n",
      "(4, 11, 14)\n",
      "(4, 11, 15)\n",
      "(4, 11, 16)\n",
      "(4, 11, 17)\n",
      "(4, 11, 18)\n",
      "(4, 11, 19)\n",
      "(4, 12, 13)\n",
      "(4, 12, 14)\n",
      "(4, 12, 15)\n",
      "(4, 12, 16)\n",
      "(4, 12, 17)\n",
      "(4, 12, 18)\n",
      "(4, 12, 19)\n",
      "(4, 13, 14)\n",
      "(4, 13, 15)\n",
      "(4, 13, 16)\n",
      "(4, 13, 17)\n",
      "(4, 13, 18)\n",
      "(4, 13, 19)\n",
      "(4, 14, 15)\n",
      "(4, 14, 16)\n",
      "(4, 14, 17)\n",
      "(4, 14, 18)\n",
      "(4, 14, 19)\n",
      "(4, 15, 16)\n",
      "(4, 15, 17)\n",
      "(4, 15, 18)\n",
      "(4, 15, 19)\n",
      "(4, 16, 17)\n",
      "(4, 16, 18)\n",
      "(4, 16, 19)\n",
      "(4, 17, 18)\n",
      "(4, 17, 19)\n",
      "(4, 18, 19)\n",
      "(5, 6, 7)\n",
      "(5, 6, 8)\n",
      "(5, 6, 9)\n",
      "(5, 6, 10)\n",
      "(5, 6, 11)\n",
      "(5, 6, 12)\n",
      "(5, 6, 13)\n",
      "(5, 6, 14)\n",
      "(5, 6, 15)\n",
      "(5, 6, 16)\n",
      "(5, 6, 17)\n",
      "(5, 6, 18)\n",
      "(5, 6, 19)\n",
      "(5, 7, 8)\n",
      "(5, 7, 9)\n",
      "(5, 7, 10)\n",
      "(5, 7, 11)\n",
      "(5, 7, 12)\n",
      "(5, 7, 13)\n",
      "(5, 7, 14)\n",
      "(5, 7, 15)\n",
      "(5, 7, 16)\n",
      "(5, 7, 17)\n",
      "(5, 7, 18)\n",
      "(5, 7, 19)\n",
      "(5, 8, 9)\n",
      "(5, 8, 10)\n",
      "(5, 8, 11)\n",
      "(5, 8, 12)\n",
      "(5, 8, 13)\n",
      "(5, 8, 14)\n",
      "(5, 8, 15)\n",
      "(5, 8, 16)\n",
      "(5, 8, 17)\n",
      "(5, 8, 18)\n",
      "(5, 8, 19)\n",
      "(5, 9, 10)\n",
      "(5, 9, 11)\n",
      "(5, 9, 12)\n",
      "(5, 9, 13)\n",
      "(5, 9, 14)\n",
      "(5, 9, 15)\n",
      "(5, 9, 16)\n",
      "(5, 9, 17)\n",
      "(5, 9, 18)\n",
      "(5, 9, 19)\n",
      "(5, 10, 11)\n",
      "(5, 10, 12)\n",
      "(5, 10, 13)\n",
      "(5, 10, 14)\n",
      "(5, 10, 15)\n",
      "(5, 10, 16)\n",
      "(5, 10, 17)\n",
      "(5, 10, 18)\n",
      "(5, 10, 19)\n",
      "(5, 11, 12)\n",
      "(5, 11, 13)\n",
      "(5, 11, 14)\n",
      "(5, 11, 15)\n",
      "(5, 11, 16)\n",
      "(5, 11, 17)\n",
      "(5, 11, 18)\n",
      "(5, 11, 19)\n",
      "(5, 12, 13)\n",
      "(5, 12, 14)\n",
      "(5, 12, 15)\n",
      "(5, 12, 16)\n",
      "(5, 12, 17)\n",
      "(5, 12, 18)\n",
      "(5, 12, 19)\n",
      "(5, 13, 14)\n",
      "(5, 13, 15)\n",
      "(5, 13, 16)\n",
      "(5, 13, 17)\n",
      "(5, 13, 18)\n",
      "(5, 13, 19)\n",
      "(5, 14, 15)\n",
      "(5, 14, 16)\n",
      "(5, 14, 17)\n",
      "(5, 14, 18)\n",
      "(5, 14, 19)\n",
      "(5, 15, 16)\n",
      "(5, 15, 17)\n",
      "(5, 15, 18)\n",
      "(5, 15, 19)\n",
      "(5, 16, 17)\n",
      "(5, 16, 18)\n",
      "(5, 16, 19)\n",
      "(5, 17, 18)\n",
      "(5, 17, 19)\n",
      "(5, 18, 19)\n",
      "(6, 7, 8)\n",
      "(6, 7, 9)\n",
      "(6, 7, 10)\n",
      "(6, 7, 11)\n",
      "(6, 7, 12)\n",
      "(6, 7, 13)\n",
      "(6, 7, 14)\n",
      "(6, 7, 15)\n",
      "(6, 7, 16)\n",
      "(6, 7, 17)\n",
      "(6, 7, 18)\n",
      "(6, 7, 19)\n",
      "(6, 8, 9)\n",
      "(6, 8, 10)\n",
      "(6, 8, 11)\n",
      "(6, 8, 12)\n",
      "(6, 8, 13)\n",
      "(6, 8, 14)\n",
      "(6, 8, 15)\n",
      "(6, 8, 16)\n",
      "(6, 8, 17)\n",
      "(6, 8, 18)\n",
      "(6, 8, 19)\n",
      "(6, 9, 10)\n",
      "(6, 9, 11)\n",
      "(6, 9, 12)\n",
      "(6, 9, 13)\n",
      "(6, 9, 14)\n",
      "(6, 9, 15)\n",
      "(6, 9, 16)\n",
      "(6, 9, 17)\n",
      "(6, 9, 18)\n",
      "(6, 9, 19)\n",
      "(6, 10, 11)\n",
      "(6, 10, 12)\n",
      "(6, 10, 13)\n",
      "(6, 10, 14)\n",
      "(6, 10, 15)\n",
      "(6, 10, 16)\n",
      "(6, 10, 17)\n",
      "(6, 10, 18)\n",
      "(6, 10, 19)\n",
      "(6, 11, 12)\n",
      "(6, 11, 13)\n",
      "(6, 11, 14)\n",
      "(6, 11, 15)\n",
      "(6, 11, 16)\n",
      "(6, 11, 17)\n",
      "(6, 11, 18)\n",
      "(6, 11, 19)\n",
      "(6, 12, 13)\n",
      "(6, 12, 14)\n",
      "(6, 12, 15)\n",
      "(6, 12, 16)\n",
      "(6, 12, 17)\n",
      "(6, 12, 18)\n",
      "(6, 12, 19)\n",
      "(6, 13, 14)\n",
      "(6, 13, 15)\n",
      "(6, 13, 16)\n",
      "(6, 13, 17)\n",
      "(6, 13, 18)\n",
      "(6, 13, 19)\n",
      "(6, 14, 15)\n",
      "(6, 14, 16)\n",
      "(6, 14, 17)\n",
      "(6, 14, 18)\n",
      "(6, 14, 19)\n",
      "(6, 15, 16)\n",
      "(6, 15, 17)\n",
      "(6, 15, 18)\n",
      "(6, 15, 19)\n",
      "(6, 16, 17)\n",
      "(6, 16, 18)\n",
      "(6, 16, 19)\n",
      "(6, 17, 18)\n",
      "(6, 17, 19)\n",
      "(6, 18, 19)\n",
      "(7, 8, 9)\n",
      "(7, 8, 10)\n",
      "(7, 8, 11)\n",
      "(7, 8, 12)\n",
      "(7, 8, 13)\n",
      "(7, 8, 14)\n",
      "(7, 8, 15)\n",
      "(7, 8, 16)\n",
      "(7, 8, 17)\n",
      "(7, 8, 18)\n",
      "(7, 8, 19)\n",
      "(7, 9, 10)\n",
      "(7, 9, 11)\n",
      "(7, 9, 12)\n",
      "(7, 9, 13)\n",
      "(7, 9, 14)\n",
      "(7, 9, 15)\n",
      "(7, 9, 16)\n",
      "(7, 9, 17)\n",
      "(7, 9, 18)\n",
      "(7, 9, 19)\n",
      "(7, 10, 11)\n",
      "(7, 10, 12)\n",
      "(7, 10, 13)\n",
      "(7, 10, 14)\n",
      "(7, 10, 15)\n",
      "(7, 10, 16)\n",
      "(7, 10, 17)\n",
      "(7, 10, 18)\n",
      "(7, 10, 19)\n",
      "(7, 11, 12)\n",
      "(7, 11, 13)\n",
      "(7, 11, 14)\n",
      "(7, 11, 15)\n",
      "(7, 11, 16)\n",
      "(7, 11, 17)\n",
      "(7, 11, 18)\n",
      "(7, 11, 19)\n",
      "(7, 12, 13)\n",
      "(7, 12, 14)\n",
      "(7, 12, 15)\n",
      "(7, 12, 16)\n",
      "(7, 12, 17)\n",
      "(7, 12, 18)\n",
      "(7, 12, 19)\n",
      "(7, 13, 14)\n",
      "(7, 13, 15)\n",
      "(7, 13, 16)\n",
      "(7, 13, 17)\n",
      "(7, 13, 18)\n",
      "(7, 13, 19)\n",
      "(7, 14, 15)\n",
      "(7, 14, 16)\n",
      "(7, 14, 17)\n",
      "(7, 14, 18)\n",
      "(7, 14, 19)\n",
      "(7, 15, 16)\n",
      "(7, 15, 17)\n",
      "(7, 15, 18)\n",
      "(7, 15, 19)\n",
      "(7, 16, 17)\n",
      "(7, 16, 18)\n",
      "(7, 16, 19)\n",
      "(7, 17, 18)\n",
      "(7, 17, 19)\n",
      "(7, 18, 19)\n",
      "(8, 9, 10)\n",
      "(8, 9, 11)\n",
      "(8, 9, 12)\n",
      "(8, 9, 13)\n",
      "(8, 9, 14)\n",
      "(8, 9, 15)\n",
      "(8, 9, 16)\n",
      "(8, 9, 17)\n",
      "(8, 9, 18)\n",
      "(8, 9, 19)\n",
      "(8, 10, 11)\n",
      "(8, 10, 12)\n",
      "(8, 10, 13)\n",
      "(8, 10, 14)\n",
      "(8, 10, 15)\n",
      "(8, 10, 16)\n",
      "(8, 10, 17)\n",
      "(8, 10, 18)\n",
      "(8, 10, 19)\n",
      "(8, 11, 12)\n",
      "(8, 11, 13)\n",
      "(8, 11, 14)\n",
      "(8, 11, 15)\n",
      "(8, 11, 16)\n",
      "(8, 11, 17)\n",
      "(8, 11, 18)\n",
      "(8, 11, 19)\n",
      "(8, 12, 13)\n",
      "(8, 12, 14)\n",
      "(8, 12, 15)\n",
      "(8, 12, 16)\n",
      "(8, 12, 17)\n",
      "(8, 12, 18)\n",
      "(8, 12, 19)\n",
      "(8, 13, 14)\n",
      "(8, 13, 15)\n",
      "(8, 13, 16)\n",
      "(8, 13, 17)\n",
      "(8, 13, 18)\n",
      "(8, 13, 19)\n",
      "(8, 14, 15)\n",
      "(8, 14, 16)\n",
      "(8, 14, 17)\n",
      "(8, 14, 18)\n",
      "(8, 14, 19)\n",
      "(8, 15, 16)\n",
      "(8, 15, 17)\n",
      "(8, 15, 18)\n",
      "(8, 15, 19)\n",
      "(8, 16, 17)\n",
      "(8, 16, 18)\n",
      "(8, 16, 19)\n",
      "(8, 17, 18)\n",
      "(8, 17, 19)\n",
      "(8, 18, 19)\n",
      "(9, 10, 11)\n",
      "(9, 10, 12)\n",
      "(9, 10, 13)\n",
      "(9, 10, 14)\n",
      "(9, 10, 15)\n",
      "(9, 10, 16)\n",
      "(9, 10, 17)\n",
      "(9, 10, 18)\n",
      "(9, 10, 19)\n",
      "(9, 11, 12)\n",
      "(9, 11, 13)\n",
      "(9, 11, 14)\n",
      "(9, 11, 15)\n",
      "(9, 11, 16)\n",
      "(9, 11, 17)\n",
      "(9, 11, 18)\n",
      "(9, 11, 19)\n",
      "(9, 12, 13)\n",
      "(9, 12, 14)\n",
      "(9, 12, 15)\n",
      "(9, 12, 16)\n",
      "(9, 12, 17)\n",
      "(9, 12, 18)\n",
      "(9, 12, 19)\n",
      "(9, 13, 14)\n",
      "(9, 13, 15)\n",
      "(9, 13, 16)\n",
      "(9, 13, 17)\n",
      "(9, 13, 18)\n",
      "(9, 13, 19)\n",
      "(9, 14, 15)\n",
      "(9, 14, 16)\n",
      "(9, 14, 17)\n",
      "(9, 14, 18)\n",
      "(9, 14, 19)\n",
      "(9, 15, 16)\n",
      "(9, 15, 17)\n",
      "(9, 15, 18)\n",
      "(9, 15, 19)\n",
      "(9, 16, 17)\n",
      "(9, 16, 18)\n",
      "(9, 16, 19)\n",
      "(9, 17, 18)\n",
      "(9, 17, 19)\n",
      "(9, 18, 19)\n",
      "(10, 11, 12)\n",
      "(10, 11, 13)\n",
      "(10, 11, 14)\n",
      "(10, 11, 15)\n",
      "(10, 11, 16)\n",
      "(10, 11, 17)\n",
      "(10, 11, 18)\n",
      "(10, 11, 19)\n",
      "(10, 12, 13)\n",
      "(10, 12, 14)\n",
      "(10, 12, 15)\n",
      "(10, 12, 16)\n",
      "(10, 12, 17)\n",
      "(10, 12, 18)\n",
      "(10, 12, 19)\n",
      "(10, 13, 14)\n",
      "(10, 13, 15)\n",
      "(10, 13, 16)\n",
      "(10, 13, 17)\n",
      "(10, 13, 18)\n",
      "(10, 13, 19)\n",
      "(10, 14, 15)\n",
      "(10, 14, 16)\n",
      "(10, 14, 17)\n",
      "(10, 14, 18)\n",
      "(10, 14, 19)\n",
      "(10, 15, 16)\n",
      "(10, 15, 17)\n",
      "(10, 15, 18)\n",
      "(10, 15, 19)\n",
      "(10, 16, 17)\n",
      "(10, 16, 18)\n",
      "(10, 16, 19)\n",
      "(10, 17, 18)\n",
      "(10, 17, 19)\n",
      "(10, 18, 19)\n",
      "(11, 12, 13)\n",
      "(11, 12, 14)\n",
      "(11, 12, 15)\n",
      "(11, 12, 16)\n",
      "(11, 12, 17)\n",
      "(11, 12, 18)\n",
      "(11, 12, 19)\n",
      "(11, 13, 14)\n",
      "(11, 13, 15)\n",
      "(11, 13, 16)\n",
      "(11, 13, 17)\n",
      "(11, 13, 18)\n",
      "(11, 13, 19)\n",
      "(11, 14, 15)\n",
      "(11, 14, 16)\n",
      "(11, 14, 17)\n",
      "(11, 14, 18)\n",
      "(11, 14, 19)\n",
      "(11, 15, 16)\n",
      "(11, 15, 17)\n",
      "(11, 15, 18)\n",
      "(11, 15, 19)\n",
      "(11, 16, 17)\n",
      "(11, 16, 18)\n",
      "(11, 16, 19)\n",
      "(11, 17, 18)\n",
      "(11, 17, 19)\n",
      "(11, 18, 19)\n",
      "(12, 13, 14)\n",
      "(12, 13, 15)\n",
      "(12, 13, 16)\n",
      "(12, 13, 17)\n",
      "(12, 13, 18)\n",
      "(12, 13, 19)\n",
      "(12, 14, 15)\n",
      "(12, 14, 16)\n",
      "(12, 14, 17)\n",
      "(12, 14, 18)\n",
      "(12, 14, 19)\n",
      "(12, 15, 16)\n",
      "(12, 15, 17)\n",
      "(12, 15, 18)\n",
      "(12, 15, 19)\n",
      "(12, 16, 17)\n",
      "(12, 16, 18)\n",
      "(12, 16, 19)\n",
      "(12, 17, 18)\n",
      "(12, 17, 19)\n",
      "(12, 18, 19)\n",
      "(13, 14, 15)\n",
      "(13, 14, 16)\n",
      "(13, 14, 17)\n",
      "(13, 14, 18)\n",
      "(13, 14, 19)\n",
      "(13, 15, 16)\n",
      "(13, 15, 17)\n",
      "(13, 15, 18)\n",
      "(13, 15, 19)\n",
      "(13, 16, 17)\n",
      "(13, 16, 18)\n",
      "(13, 16, 19)\n",
      "(13, 17, 18)\n",
      "(13, 17, 19)\n",
      "(13, 18, 19)\n",
      "(14, 15, 16)\n",
      "(14, 15, 17)\n",
      "(14, 15, 18)\n",
      "(14, 15, 19)\n",
      "(14, 16, 17)\n",
      "(14, 16, 18)\n",
      "(14, 16, 19)\n",
      "(14, 17, 18)\n",
      "(14, 17, 19)\n",
      "(14, 18, 19)\n",
      "(15, 16, 17)\n",
      "(15, 16, 18)\n",
      "(15, 16, 19)\n",
      "(15, 17, 18)\n",
      "(15, 17, 19)\n",
      "(15, 18, 19)\n",
      "(16, 17, 18)\n",
      "(16, 17, 19)\n",
      "(16, 18, 19)\n",
      "(17, 18, 19)\n"
     ]
    }
   ],
   "source": [
    "from itertools import combinations\n",
    "for t in combinations(range(1,20), 3):\n",
    "    print(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "filter_cat_features: remove ['13', '9', '14', '18', '20', '10', '1', '15', '28', '7']\n",
      "['8', '19', '4', '0', '11', '17', '3', '12', '27', '24', '6', '23', '25', '5', '21', '16', '29', '22', '26', '2']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "17    0.061162\n",
       "26    0.050925\n",
       "25    0.049237\n",
       "19    0.041033\n",
       "6     0.038146\n",
       "23    0.034957\n",
       "4     0.029672\n",
       "22    0.029008\n",
       "27    0.026958\n",
       "8     0.026499\n",
       "0     0.025505\n",
       "29    0.025129\n",
       "24    0.024787\n",
       "5     0.021390\n",
       "3     0.015145\n",
       "12    0.014918\n",
       "2     0.014637\n",
       "21    0.013757\n",
       "11    0.011340\n",
       "16    0.011180\n",
       "13    0.010194\n",
       "9     0.009801\n",
       "14    0.009730\n",
       "18    0.007901\n",
       "20    0.005520\n",
       "10    0.005243\n",
       "1     0.005179\n",
       "15    0.004222\n",
       "28    0.003157\n",
       "7     0.002480\n",
       "dtype: float64"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.DataFrame(np.random.randint(1,5,(50,30)), columns=[str(i) for i in range(30)])\n",
    "labels = np.random.randint(0,2,(50,))\n",
    "fs = FeatureSelector(data, labels)\n",
    "\n",
    "def test_func1(train_x, train_y, test_x, test_y):\n",
    "    return random.random()\n",
    "\n",
    "def test_func2(train_x, train_y, test_x, test_y):\n",
    "    return [(str(i), random.random()) for i in range(30)]\n",
    "\n",
    "# fs.wrapper_selector(test_func1, remain_num=25).embedded_selector(test_func2, remain_num=23).left_features_\n",
    "print(fs.filter_cat_features([str(i) for i in range(30)], top_k=20).left_features_)\n",
    "fs.info_gain_rates_.sort_values(ascending=False)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def print_function(x):\n",
    "    print(x)\n",
    "    \n",
    "def print_warning(x):\n",
    "    print(x)\n",
    "    \n",
    "def cal_entroy(x):\n",
    "    '''\n",
    "    Compute the shannon entropy.\n",
    "    \n",
    "    Parameters\n",
    "    ----------\n",
    "    x : array-like\n",
    "        The list value of the variant.\n",
    "        \n",
    "    Returns\n",
    "    -------\n",
    "    entroy : float\n",
    "        The shannon entropy value.\n",
    "    '''\n",
    "    counts = {} \n",
    "    length = len(x)\n",
    "    for c in x:\n",
    "        counts[c] = counts.get(c, 0) + 1\n",
    "    entroy = 0.0\n",
    "    for count in counts.values():\n",
    "        p = count / float(length)\n",
    "        entroy -= p * np.log2(p) if p != 0 else 0.0\n",
    "    return entroy\n",
    "\n",
    "def cal_info_gain_rate(x, y):\n",
    "    '''\n",
    "    Compute the info gain rate.\n",
    "    \n",
    "    Parameters\n",
    "    ----------\n",
    "    x : array-like\n",
    "        The feature variant list.\n",
    "    y : array-like\n",
    "        The target variant list.\n",
    "        \n",
    "    Returns\n",
    "    -------\n",
    "    igr : float\n",
    "        The info gain rate value.\n",
    "    '''\n",
    "    x_entropy = cal_entroy(x)\n",
    "    if x_entropy == 0.0:\n",
    "        return 0.0\n",
    "    value2list = {}\n",
    "    length = len(x)\n",
    "    for i,e in enumerate(x):\n",
    "        value2list[e] = value2list.get(e, [])\n",
    "        value2list.get(e).append(y[i])\n",
    "    igr = 0.0\n",
    "    for e in value2list.keys():\n",
    "        igr += len(value2list[e]) / float(length) * cal_entroy(value2list[e])\n",
    "    igr = (cal_entroy(y) - igr) / x_entropy\n",
    "    return igr"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
